import random

from wxauto import *

def send(who, msg):
    wx.SendMsg(msg, who)

messages = []
with open('message.txt',encoding='utf-8') as f:
    for line in f:
        messages.append(line)


# 获取当前微信客户端
wx = WeChat()

# 获取会话列表
wx.GetSessionList()

# for line in messages:
#     who, msg = line.split('@@')
#     send(who, msg)


# 向某人发送消息（以`文件传输助手`为例）



# # 向某人发送文件（以`文件传输助手`为例，发送三个不同类型文件）
# files = [
#     'D:/test/wxauto.py',
#     'D:/test/pic.png',
#     'D:/test/files.rar'
# ]
# who = '文件传输助手'
# wx.SendFiles(filepath=files, who=who)  # 向`文件传输助手`发送上述三个文件


# 下载当前聊天窗口的聊天记录及图片
# msgs = wx.GetAllMessage(savepic=True)   # 获取聊天记录，及自动下载图片
eat = [ '糖醋里脊', '西红柿炒蛋', '土豆粉', '酸辣粉', '米线', '把子肉', '胡辣汤', '麻辣烫', '排骨米饭']
index = random.randint(0, len(eat)-1)
print(eat[index])

who = '2024软件技术4班陈姝含'
wx.AddListenChat(who)
while True:
    msg = wx.GetListenMessage()
    for key, value in msg.items():
        if value and len(value)>0:
            msg = value[-1].content
            if '吃什么' in msg:
                index = random.randint(0, len(eat)-1)
                wx.SendMsg(eat[index], who)


